package org.destiny.msglipse;

import java.io.InputStream;
import java.util.Random;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

public class ResourceUtil {
	static final Random random = new Random();
	static final String[] names = {"sky","lake","mount","wind","sun","rock","shine","dragon","fire"};

	public static Image getSharedImage(String symbolicName) {
		try {
			return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(symbolicName).createImage();
		} catch (Exception e) {
			return null;
		}
	}

	public static Image getMyImage(Display display, String name) {
		try {
			InputStream res = ResourceUtil.class.getClassLoader().getResourceAsStream("icons/" + name);
			return new Image(display, res);
		} catch (Exception e) {
			return new Image(display, "icons/" + name);
		}
	}

	public static String randomName() {
		return names[random.nextInt(9)]+"-"+random.nextInt(1000);
	}
}
